use IstoreInternet;
	
	IF (NOT EXISTS (SELECT * 
                 FROM INFORMATION_SCHEMA.TABLES 
                 WHERE TABLE_SCHEMA = 'dbo' 
                 AND  TABLE_NAME = 'Attribute'))
		BEGIN
				CREATE TABLE [dbo].[Attribute](
				[attrId] [int] IDENTITY(1,1) NOT NULL,
				[attrName] [nvarchar](150) NOT NULL,
				[attrDescription] [nvarchar](500) NULL,
			 CONSTRAINT [PK_Attribute] PRIMARY KEY CLUSTERED 
			(
				[attrId] ASC
			)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
			) ON [PRIMARY]
		END
	
	
	
	IF (NOT EXISTS (SELECT * 
                 FROM INFORMATION_SCHEMA.TABLES 
                 WHERE TABLE_SCHEMA = 'dbo' 
                 AND  TABLE_NAME = 'AttrValue'))
		BEGIN
			CREATE TABLE [dbo].[AttrValue](
				[attrValueId] [int] IDENTITY(1,1) NOT NULL,
				[attrId] [int] NOT NULL,
				[attrValueName] [nvarchar](250) NULL,
				[attrValueDescription] [nvarchar](500) NULL,
			 CONSTRAINT [PK_AttrValue] PRIMARY KEY CLUSTERED 
			(
				[attrValueId] ASC
			)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
			) ON [PRIMARY]

			ALTER TABLE [dbo].[AttrValue]  WITH CHECK ADD  CONSTRAINT [FK_AttrValue_Attribute] FOREIGN KEY([attrId])
			REFERENCES [dbo].[Attribute] ([attrId])
			ALTER TABLE [dbo].[AttrValue] CHECK CONSTRAINT [FK_AttrValue_Attribute]
		END
	
	
	
	IF (NOT EXISTS (SELECT * 
                 FROM INFORMATION_SCHEMA.TABLES 
                 WHERE TABLE_SCHEMA = 'dbo' 
                 AND  TABLE_NAME = 'CityOrRegion'))
	BEGIN
		CREATE TABLE [dbo].[CityOrRegion](
			[cityOrRegionId] [int] IDENTITY(1,1) NOT NULL,
			[cityOrRegionName] [nvarchar](100) NOT NULL,
		 CONSTRAINT [PK_cityOrRegion] PRIMARY KEY CLUSTERED 
		(
			[cityOrRegionId] ASC
		)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
		) ON [PRIMARY]
	END
	
	
	
	IF (NOT EXISTS (SELECT * 
                 FROM INFORMATION_SCHEMA.TABLES 
                 WHERE TABLE_SCHEMA = 'dbo' 
                 AND  TABLE_NAME = 'Customer'))
	BEGIN
		CREATE TABLE [dbo].[Customer](
			[customerId] [int] IDENTITY(1,1) NOT NULL,
			[organisationOrPerson] [bit] NOT NULL,
			[organisationName] [nvarchar](100) NULL,
			[gender] [nvarchar](1) NULL,
			[firstName] [nvarchar](100) NULL,
			[middleName] [nvarchar](100) NULL,
			[lastName] [nvarchar](100) NULL,
			[emailPost] [nvarchar](100) NULL,
			[phoneNumber] [nvarchar](25) NULL,
			[mobilePhoneNumber] [nvarchar](25) NULL,
			[dateOfBirth] [date] NULL,
			[postIndex] [nvarchar](10) NULL,
		 CONSTRAINT [PK_Customer] PRIMARY KEY CLUSTERED 
		(
			[customerId] ASC
		)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
		) ON [PRIMARY]
	END
	
	
	
	IF (NOT EXISTS (SELECT * 
                 FROM INFORMATION_SCHEMA.TABLES 
                 WHERE TABLE_SCHEMA = 'dbo' 
                 AND  TABLE_NAME = 'CustomerAccount'))
	BEGIN
			CREATE TABLE [dbo].[CustomerAccount](
			[customerId] [int] NOT NULL,
			[loginCustomer] [nvarchar](50) NOT NULL,
			[passwordCustomer] [nvarchar](50) NOT NULL
		) ON [PRIMARY]

		ALTER TABLE [dbo].[CustomerAccount]  WITH CHECK ADD  CONSTRAINT [FK_CustomerAccount_Customer] FOREIGN KEY([customerId])
		REFERENCES [dbo].[Customer] ([customerId])

		ALTER TABLE [dbo].[CustomerAccount] CHECK CONSTRAINT [FK_CustomerAccount_Customer]
	END
	
	
	
	IF (NOT EXISTS (SELECT * 
                 FROM INFORMATION_SCHEMA.TABLES 
                 WHERE TABLE_SCHEMA = 'dbo' 
                 AND  TABLE_NAME = 'CustomerAddress'))
	BEGIN
				CREATE TABLE [dbo].[CustomerAddress](
				[addressId] [int] IDENTITY(1,1) NOT NULL,
				[customerId] [int] NOT NULL,
				[cityOrRegionId] [int] NOT NULL,
				[address] [nvarchar](150) NULL,
			 CONSTRAINT [PK_CustomerAddress] PRIMARY KEY CLUSTERED 
			(
				[addressId] ASC
			)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
			) ON [PRIMARY]


			ALTER TABLE [dbo].[CustomerAddress]  WITH CHECK ADD  CONSTRAINT [FK_CustomerAddress_CityOrRegion] FOREIGN KEY([cityOrRegionId])
			REFERENCES [dbo].[CityOrRegion] ([cityOrRegionId])

			ALTER TABLE [dbo].[CustomerAddress] CHECK CONSTRAINT [FK_CustomerAddress_CityOrRegion]

			ALTER TABLE [dbo].[CustomerAddress]  WITH CHECK ADD  CONSTRAINT [FK_CustomerAddress_Customer] FOREIGN KEY([customerId])
			REFERENCES [dbo].[Customer] ([customerId])

			ALTER TABLE [dbo].[CustomerAddress] CHECK CONSTRAINT [FK_CustomerAddress_Customer]
	END
	
	
	
	IF (NOT EXISTS (SELECT * 
                 FROM INFORMATION_SCHEMA.TABLES 
                 WHERE TABLE_SCHEMA = 'dbo' 
                 AND  TABLE_NAME = 'Order'))
	BEGIN
							CREATE TABLE [dbo].[Order](
				[orderId] [int] IDENTITY(1,1) NOT NULL,
				[customerId] [int] NOT NULL,
				[orderStatusCode] [nvarchar](50) NULL,
				[orderState] [nvarchar](50) NULL,
				[orderDetails] [nvarchar](150) NULL,
			 CONSTRAINT [PK_Order] PRIMARY KEY CLUSTERED 
			(
				[orderId] ASC
			)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
			) ON [PRIMARY]


			ALTER TABLE [dbo].[Order]  WITH CHECK ADD  CONSTRAINT [FK_Order_Customer] FOREIGN KEY([customerId])
			REFERENCES [dbo].[Customer] ([customerId])

			ALTER TABLE [dbo].[Order] CHECK CONSTRAINT [FK_Order_Customer]
	END
	
	
	
	
	IF (NOT EXISTS (SELECT * 
                 FROM INFORMATION_SCHEMA.TABLES 
                 WHERE TABLE_SCHEMA = 'dbo' 
                 AND  TABLE_NAME = 'PaymentMethod'))
	BEGIN
		CREATE TABLE [dbo].[PaymentMethod](
			[paymentMethodId] [int] IDENTITY(1,1) NOT NULL,
			[paymentMethodDescription] [nvarchar](150) NULL,
		 CONSTRAINT [PK_PaymentMethod] PRIMARY KEY CLUSTERED 
		(
			[paymentMethodId] ASC
		)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
		) ON [PRIMARY]
	END
	
	
	
	
	IF (NOT EXISTS (SELECT * 
                 FROM INFORMATION_SCHEMA.TABLES 
                 WHERE TABLE_SCHEMA = 'dbo' 
                 AND  TABLE_NAME = 'ProductRatingItem'))
	BEGIN
				CREATE TABLE [dbo].[ProductRatingItem](
			[productRatingItemId] [int] IDENTITY(1,1) NOT NULL,
			[rating] [nvarchar](50) NOT NULL,
		 CONSTRAINT [PK_ProductRatingItem] PRIMARY KEY CLUSTERED 
		(
			[productRatingItemId] ASC
		)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
		) ON [PRIMARY]
	END
	
	
	
	IF (NOT EXISTS (SELECT * 
                 FROM INFORMATION_SCHEMA.TABLES 
                 WHERE TABLE_SCHEMA = 'dbo' 
                 AND  TABLE_NAME = 'ProductType'))
	BEGIN
				CREATE TABLE [dbo].[ProductType](
			[productTypeId] [int] IDENTITY(1,1) NOT NULL,
			[productTypeName] [nvarchar](150) NOT NULL,
			[productTypeDescription] [nvarchar](500) NULL,
		 CONSTRAINT [PK_ProductType] PRIMARY KEY CLUSTERED 
		(
			[productTypeId] ASC
		)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
		) ON [PRIMARY]
	END
	
	
	
	
	IF (NOT EXISTS (SELECT * 
                 FROM INFORMATION_SCHEMA.TABLES 
                 WHERE TABLE_SCHEMA = 'dbo' 
                 AND  TABLE_NAME = 'ProductTypeAttrValue'))
	BEGIN
					CREATE TABLE [dbo].[ProductTypeAttrValue](
				[productTypeAttrValueId] [int] IDENTITY(1,1) NOT NULL,
				[productTypeId] [int] NOT NULL,
				[attrValueId] [int] NOT NULL,
			 CONSTRAINT [PK_ProductTypeAttrValue] PRIMARY KEY CLUSTERED 
			(
				[productTypeAttrValueId] ASC
			)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
			) ON [PRIMARY]

			ALTER TABLE [dbo].[ProductTypeAttrValue]  WITH CHECK ADD  CONSTRAINT [FK_ProductTypeAttrValue_AttrValue] FOREIGN KEY([attrValueId])
			REFERENCES [dbo].[AttrValue] ([attrValueId])

			ALTER TABLE [dbo].[ProductTypeAttrValue] CHECK CONSTRAINT [FK_ProductTypeAttrValue_AttrValue]

			ALTER TABLE [dbo].[ProductTypeAttrValue]  WITH CHECK ADD  CONSTRAINT [FK_ProductTypeAttrValue_ProductType] FOREIGN KEY([productTypeId])
			REFERENCES [dbo].[ProductType] ([productTypeId])

			ALTER TABLE [dbo].[ProductTypeAttrValue] CHECK CONSTRAINT [FK_ProductTypeAttrValue_ProductType]
	END
	
	
	
	
	IF (NOT EXISTS (SELECT * 
                 FROM INFORMATION_SCHEMA.TABLES 
                 WHERE TABLE_SCHEMA = 'dbo' 
                 AND  TABLE_NAME = 'WishList'))
	BEGIN
				CREATE TABLE [dbo].[WishList](
			[wishListId] [int] IDENTITY(1,1) NOT NULL,
			[customerId] [int] NOT NULL,
		 CONSTRAINT [PK_WishList] PRIMARY KEY CLUSTERED 
		(
			[wishListId] ASC
		)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
		) ON [PRIMARY]

		ALTER TABLE [dbo].[WishList]  WITH CHECK ADD  CONSTRAINT [FK_WishList_Customer] FOREIGN KEY([customerId])
		REFERENCES [dbo].[Customer] ([customerId])

		ALTER TABLE [dbo].[WishList] CHECK CONSTRAINT [FK_WishList_Customer]
	END
	
	
	
	
	IF (NOT EXISTS (SELECT * 
                 FROM INFORMATION_SCHEMA.TABLES 
                 WHERE TABLE_SCHEMA = 'dbo' 
                 AND  TABLE_NAME = 'CustomerPaymentMethod'))
	BEGIN
				CREATE TABLE [dbo].[CustomerPaymentMethod](
			[customerPaymentMethodId] [int] IDENTITY(1,1) NOT NULL,
			[paymentMethodId] [int] NOT NULL,
			[customerId] [int] NOT NULL,
			[paymentDetails] [nvarchar](500) NULL,
		 CONSTRAINT [PK_CustomerPaymentMethod] PRIMARY KEY CLUSTERED 
		(
			[customerPaymentMethodId] ASC
		)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
		) ON [PRIMARY]

		ALTER TABLE [dbo].[CustomerPaymentMethod]  WITH CHECK ADD  CONSTRAINT [FK_CustomerPaymentMethod_Customer] FOREIGN KEY([customerId])
		REFERENCES [dbo].[Customer] ([customerId])

		ALTER TABLE [dbo].[CustomerPaymentMethod] CHECK CONSTRAINT [FK_CustomerPaymentMethod_Customer]

		ALTER TABLE [dbo].[CustomerPaymentMethod]  WITH CHECK ADD  CONSTRAINT [FK_CustomerPaymentMethod_PaymentMethod] FOREIGN KEY([paymentMethodId])
		REFERENCES [dbo].[PaymentMethod] ([paymentMethodId])

		ALTER TABLE [dbo].[CustomerPaymentMethod] CHECK CONSTRAINT [FK_CustomerPaymentMethod_PaymentMethod]
	END
	
	
	
	IF (NOT EXISTS (SELECT * 
                 FROM INFORMATION_SCHEMA.TABLES 
                 WHERE TABLE_SCHEMA = 'dbo' 
                 AND  TABLE_NAME = 'Invoice'))
	BEGIN
				CREATE TABLE [dbo].[Invoice](
			[invoiceNumber] [int] IDENTITY(1,1) NOT NULL,
			[orderId] [int] NOT NULL,
			[invoiceDate] [datetime] NULL,
			[invoiceDetails] [nvarchar](500) NULL,
		 CONSTRAINT [PK_Invoice] PRIMARY KEY CLUSTERED 
		(
			[invoiceNumber] ASC
		)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
		) ON [PRIMARY]
	END
	
	
	
	
	IF (NOT EXISTS (SELECT * 
                 FROM INFORMATION_SCHEMA.TABLES 
                 WHERE TABLE_SCHEMA = 'dbo' 
                 AND  TABLE_NAME = 'Payment'))
	BEGIN
					CREATE TABLE [dbo].[Payment](
				[paymentId] [int] IDENTITY(1,1) NOT NULL,
				[invoiceNumber] [int] NOT NULL,
				[paymentDate] [datetime] NULL,
				[paymentAmount] [decimal](9, 2) NULL,
			 CONSTRAINT [PK_Payment] PRIMARY KEY CLUSTERED 
			(
				[paymentId] ASC
			)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
			) ON [PRIMARY]


			ALTER TABLE [dbo].[Payment]  WITH CHECK ADD  CONSTRAINT [FK_Payment_Invoice] FOREIGN KEY([invoiceNumber])
			REFERENCES [dbo].[Invoice] ([invoiceNumber])

			ALTER TABLE [dbo].[Payment] CHECK CONSTRAINT [FK_Payment_Invoice]
	END
	
	
	
	
	IF (NOT EXISTS (SELECT * 
                 FROM INFORMATION_SCHEMA.TABLES 
                 WHERE TABLE_SCHEMA = 'dbo' 
                 AND  TABLE_NAME = 'Product'))
	BEGIN
				CREATE TABLE [dbo].[Product](
			[productId] [int] IDENTITY(1,1) NOT NULL,
			[productTypeId] [int] NOT NULL,
			[productName] [nvarchar](250) NOT NULL,
			[productDescription] [nvarchar](500) NULL,
			[productPrice] [decimal](9, 2) NOT NULL,
			[productSmallImage] [nvarchar](500) NULL,
			[productMiddleImage] [nvarchar](500) NULL,
			[productBigImage] [nvarchar](500) NULL,
			[productWarranty] [int] NULL,
		 CONSTRAINT [PK_Product] PRIMARY KEY CLUSTERED 
		(
			[productId] ASC
		)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
		) ON [PRIMARY]


		ALTER TABLE [dbo].[Product]  WITH CHECK ADD  CONSTRAINT [FK_Product_ProductType] FOREIGN KEY([productTypeId])
		REFERENCES [dbo].[ProductType] ([productTypeId])

		ALTER TABLE [dbo].[Product] CHECK CONSTRAINT [FK_Product_ProductType]
	END
	
	
	
	
	IF (NOT EXISTS (SELECT * 
                 FROM INFORMATION_SCHEMA.TABLES 
                 WHERE TABLE_SCHEMA = 'dbo' 
                 AND  TABLE_NAME = 'Product'))
	BEGIN
				CREATE TABLE [dbo].[Product](
			[productId] [int] IDENTITY(1,1) NOT NULL,
			[productTypeId] [int] NOT NULL,
			[productName] [nvarchar](250) NOT NULL,
			[productDescription] [nvarchar](500) NULL,
			[productPrice] [decimal](9, 2) NOT NULL,
			[productSmallImage] [nvarchar](500) NULL,
			[productMiddleImage] [nvarchar](500) NULL,
			[productBigImage] [nvarchar](500) NULL,
		 CONSTRAINT [PK_Product] PRIMARY KEY CLUSTERED 
		(
			[productId] ASC
		)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
		) ON [PRIMARY]


		ALTER TABLE [dbo].[Product]  WITH CHECK ADD  CONSTRAINT [FK_Product_ProductType] FOREIGN KEY([productTypeId])
		REFERENCES [dbo].[ProductType] ([productTypeId])

		ALTER TABLE [dbo].[Product] CHECK CONSTRAINT [FK_Product_ProductType]
	END
	
	
	
	
	IF (NOT EXISTS (SELECT * 
                 FROM INFORMATION_SCHEMA.TABLES 
                 WHERE TABLE_SCHEMA = 'dbo' 
                 AND  TABLE_NAME = 'ProductAttrValue'))
	BEGIN
					CREATE TABLE [dbo].[ProductAttrValue](
				[productId] [int] NOT NULL,
				[attrValueId] [int] NOT NULL
			) ON [PRIMARY]


			ALTER TABLE [dbo].[ProductAttrValue]  WITH CHECK ADD  CONSTRAINT [FK_ProductAttrValue_AttrValue] FOREIGN KEY([attrValueId])
			REFERENCES [dbo].[AttrValue] ([attrValueId])

			ALTER TABLE [dbo].[ProductAttrValue] CHECK CONSTRAINT [FK_ProductAttrValue_AttrValue]

			ALTER TABLE [dbo].[ProductAttrValue]  WITH CHECK ADD  CONSTRAINT [FK_ProductAttrValue_Product] FOREIGN KEY([productId])
			REFERENCES [dbo].[Product] ([productId])

			ALTER TABLE [dbo].[ProductAttrValue] CHECK CONSTRAINT [FK_ProductAttrValue_Product]
	END
	
	
	
	
	IF (NOT EXISTS (SELECT * 
                 FROM INFORMATION_SCHEMA.TABLES 
                 WHERE TABLE_SCHEMA = 'dbo' 
                 AND  TABLE_NAME = 'ProductComment'))
	BEGIN
				CREATE TABLE [dbo].[ProductComment](
			[productId] [int] NOT NULL,
			[customerId] [int] NOT NULL,
			[productComment] [nvarchar](500) NULL,
			[productCommentDignity] [nvarchar](500) NULL,
			[productCommentShortcoming] [nvarchar](500) NULL
		) ON [PRIMARY]


		ALTER TABLE [dbo].[ProductComment]  WITH CHECK ADD  CONSTRAINT [FK_ProductComment_Customer] FOREIGN KEY([customerId])
		REFERENCES [dbo].[Customer] ([customerId])

		ALTER TABLE [dbo].[ProductComment] CHECK CONSTRAINT [FK_ProductComment_Customer]

		ALTER TABLE [dbo].[ProductComment]  WITH CHECK ADD  CONSTRAINT [FK_ProductComment_Product] FOREIGN KEY([productId])
		REFERENCES [dbo].[Product] ([productId])

		ALTER TABLE [dbo].[ProductComment] CHECK CONSTRAINT [FK_ProductComment_Product]
	END
	
	
	
	
	IF (NOT EXISTS (SELECT * 
                 FROM INFORMATION_SCHEMA.TABLES 
                 WHERE TABLE_SCHEMA = 'dbo' 
                 AND  TABLE_NAME = 'ProductPhoto'))
	BEGIN
				CREATE TABLE [dbo].[ProductPhoto](
			[productId] [int] NOT NULL,
			[productPhoto] [nvarchar](500) NULL
		) ON [PRIMARY]


		ALTER TABLE [dbo].[ProductPhoto]  WITH CHECK ADD  CONSTRAINT [FK_ProductPhoto_Product] FOREIGN KEY([productId])
		REFERENCES [dbo].[Product] ([productId])

		ALTER TABLE [dbo].[ProductPhoto] CHECK CONSTRAINT [FK_ProductPhoto_Product]
	END
	
	
	
	
	IF (NOT EXISTS (SELECT * 
                 FROM INFORMATION_SCHEMA.TABLES 
                 WHERE TABLE_SCHEMA = 'dbo' 
                 AND  TABLE_NAME = 'ProductWatchingStatistic'))
	BEGIN
				CREATE TABLE [dbo].[ProductWatchingStatistic](
			[productId] [int] NOT NULL,
			[countWatching] [int] NOT NULL
		) ON [PRIMARY]


		ALTER TABLE [dbo].[ProductWatchingStatistic]  WITH CHECK ADD  CONSTRAINT [FK_ProductWatchingStatistic_Product] FOREIGN KEY([productId])
		REFERENCES [dbo].[Product] ([productId])

		ALTER TABLE [dbo].[ProductWatchingStatistic] CHECK CONSTRAINT [FK_ProductWatchingStatistic_Product]

		ALTER TABLE [dbo].[ProductWatchingStatistic] ADD  CONSTRAINT [DF_ProductWatchingStatistic_countWatching]  DEFAULT ((0)) FOR [countWatching]
	END
	
	
	
	
	IF (NOT EXISTS (SELECT * 
                 FROM INFORMATION_SCHEMA.TABLES 
                 WHERE TABLE_SCHEMA = 'dbo' 
                 AND  TABLE_NAME = 'ProductRating'))
	BEGIN
				CREATE TABLE [dbo].[ProductRating](
			[productId] [int] NOT NULL,
			[estimateCount] [int] NOT NULL,
			[productRatingItemId] [int] NOT NULL,
			[customerId] [int] NULL
		) ON [PRIMARY]


		ALTER TABLE [dbo].[ProductRating]  WITH CHECK ADD  CONSTRAINT [FK_ProductRating_Customer] FOREIGN KEY([customerId])
		REFERENCES [dbo].[Customer] ([customerId])

		ALTER TABLE [dbo].[ProductRating] CHECK CONSTRAINT [FK_ProductRating_Customer]

		ALTER TABLE [dbo].[ProductRating]  WITH CHECK ADD  CONSTRAINT [FK_ProductRating_Product] FOREIGN KEY([productId])
		REFERENCES [dbo].[Product] ([productId])

		ALTER TABLE [dbo].[ProductRating] CHECK CONSTRAINT [FK_ProductRating_Product]

		ALTER TABLE [dbo].[ProductRating]  WITH CHECK ADD  CONSTRAINT [FK_ProductRating_ProductRatingItem] FOREIGN KEY([productRatingItemId])
		REFERENCES [dbo].[ProductRatingItem] ([productRatingItemId])

		ALTER TABLE [dbo].[ProductRating] CHECK CONSTRAINT [FK_ProductRating_ProductRatingItem]

		ALTER TABLE [dbo].[ProductRating] ADD  CONSTRAINT [DF_ProductRating_estimateCount]  DEFAULT ((0)) FOR [estimateCount]
	END
	
	
	
	
	IF (NOT EXISTS (SELECT * 
                 FROM INFORMATION_SCHEMA.TABLES 
                 WHERE TABLE_SCHEMA = 'dbo' 
                 AND  TABLE_NAME = 'Shipment'))
	BEGIN
				CREATE TABLE [dbo].[Shipment](
			[shipmentId] [int] IDENTITY(1,1) NOT NULL,
			[orderId] [int] NOT NULL,
			[invoiceNumber] [int] NOT NULL,
			[shipmentStockNumber] [int] NOT NULL,
			[shipmentDetails] [nvarchar](250) NULL,
		 CONSTRAINT [PK_Shipment] PRIMARY KEY CLUSTERED 
		(
			[shipmentId] ASC
		)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
		) ON [PRIMARY]

		ALTER TABLE [dbo].[Shipment]  WITH CHECK ADD  CONSTRAINT [FK_Shipment_Invoice] FOREIGN KEY([invoiceNumber])
		REFERENCES [dbo].[Invoice] ([invoiceNumber])

		ALTER TABLE [dbo].[Shipment] CHECK CONSTRAINT [FK_Shipment_Invoice]

		ALTER TABLE [dbo].[Shipment]  WITH CHECK ADD  CONSTRAINT [FK_Shipment_Order] FOREIGN KEY([orderId])
		REFERENCES [dbo].[Order] ([orderId])

		ALTER TABLE [dbo].[Shipment] CHECK CONSTRAINT [FK_Shipment_Order]
	END
	
	
	
	IF (NOT EXISTS (SELECT * 
                 FROM INFORMATION_SCHEMA.TABLES 
                 WHERE TABLE_SCHEMA = 'dbo' 
                 AND  TABLE_NAME = 'WishListProduct'))
	BEGIN
				CREATE TABLE [dbo].[WishListProduct](
			[wishListId] [int] NOT NULL,
			[productId] [int] NOT NULL,
			[addedDate] [datetime] NULL
		) ON [PRIMARY]


		ALTER TABLE [dbo].[WishListProduct]  WITH CHECK ADD  CONSTRAINT [FK_WishListProduct_Product] FOREIGN KEY([productId])
		REFERENCES [dbo].[Product] ([productId])

		ALTER TABLE [dbo].[WishListProduct] CHECK CONSTRAINT [FK_WishListProduct_Product]

		ALTER TABLE [dbo].[WishListProduct]  WITH CHECK ADD  CONSTRAINT [FK_WishListProduct_WishList] FOREIGN KEY([wishListId])
		REFERENCES [dbo].[WishList] ([wishListId])

		ALTER TABLE [dbo].[WishListProduct] CHECK CONSTRAINT [FK_WishListProduct_WishList]
	END
	
	
	
	
	IF (NOT EXISTS (SELECT * 
                 FROM INFORMATION_SCHEMA.TABLES 
                 WHERE TABLE_SCHEMA = 'dbo' 
                 AND  TABLE_NAME = 'OrderItem'))
	BEGIN
				CREATE TABLE [dbo].[OrderItem](
			[orderItemId] [int] IDENTITY(1,1) NOT NULL,
			[productId] [int] NOT NULL,
			[orderId] [int] NOT NULL,
			[orderItemQuantity] [int] NULL,
			[orderItemPrice] [decimal](9, 2) NULL,
			[RMANumber] [nvarchar](50) NULL,
			[RMAIssuedBy] [nvarchar](50) NULL,
			[RMAIssuedDate] [datetime] NULL,
		 CONSTRAINT [PK_OrderItem] PRIMARY KEY CLUSTERED 
		(
			[orderItemId] ASC
		)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
		) ON [PRIMARY]


		ALTER TABLE [dbo].[OrderItem]  WITH CHECK ADD  CONSTRAINT [FK_OrderItem_Order] FOREIGN KEY([orderId])
		REFERENCES [dbo].[Order] ([orderId])

		ALTER TABLE [dbo].[OrderItem] CHECK CONSTRAINT [FK_OrderItem_Order]

		ALTER TABLE [dbo].[OrderItem]  WITH CHECK ADD  CONSTRAINT [FK_OrderItem_Product] FOREIGN KEY([productId])
		REFERENCES [dbo].[Product] ([productId])

		ALTER TABLE [dbo].[OrderItem] CHECK CONSTRAINT [FK_OrderItem_Product]
	END
	
	
	
	
	IF (NOT EXISTS (SELECT * 
                 FROM INFORMATION_SCHEMA.TABLES 
                 WHERE TABLE_SCHEMA = 'dbo' 
                 AND  TABLE_NAME = 'ShipmentItem'))
	BEGIN
				CREATE TABLE [dbo].[ShipmentItem](
			[shipmentId] [int] NOT NULL,
			[orderItemId] [int] NOT NULL
		) ON [PRIMARY]


		ALTER TABLE [dbo].[ShipmentItem]  WITH CHECK ADD  CONSTRAINT [FK_ShipmentItem_OrderItem] FOREIGN KEY([orderItemId])
		REFERENCES [dbo].[OrderItem] ([orderItemId])

		ALTER TABLE [dbo].[ShipmentItem] CHECK CONSTRAINT [FK_ShipmentItem_OrderItem]

		ALTER TABLE [dbo].[ShipmentItem]  WITH CHECK ADD  CONSTRAINT [FK_ShipmentItem_Shipment] FOREIGN KEY([shipmentId])
		REFERENCES [dbo].[Shipment] ([shipmentId])

		ALTER TABLE [dbo].[ShipmentItem] CHECK CONSTRAINT [FK_ShipmentItem_Shipment]
	END
	
	
	
	
	IF (NOT EXISTS (SELECT * 
                 FROM INFORMATION_SCHEMA.TABLES 
                 WHERE TABLE_SCHEMA = 'dbo' 
                 AND  TABLE_NAME = 'ShoppingCart'))
	BEGIN
				CREATE TABLE [dbo].[ShoppingCart](
			[shoppingCartId] [int] IDENTITY(1,1) NOT NULL,
			[customerId] [int] NOT NULL,
			[orderItemId] [int] NOT NULL,
			[shipmentId] [int] NOT NULL,
			[createDate] [datetime] NOT NULL,
		 CONSTRAINT [PK_ShoppingCart] PRIMARY KEY CLUSTERED 
		(
			[shoppingCartId] ASC
		)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
		) ON [PRIMARY]


		ALTER TABLE [dbo].[ShoppingCart]  WITH CHECK ADD  CONSTRAINT [FK_ShoppingCart_Customer] FOREIGN KEY([customerId])
		REFERENCES [dbo].[Customer] ([customerId])

		ALTER TABLE [dbo].[ShoppingCart] CHECK CONSTRAINT [FK_ShoppingCart_Customer]
	END